package com.bocai.test;

import net.sf.json.JSONObject;

import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.*;

public class test {

    public static void main(String[] args) {
        Long beginTime = System.currentTimeMillis() + 86400 * 1000 * 4;
        int random = (int) ((Math.random() * 9 + 1) * 100000);
//        System.out.println("str=" + random);
//        getSum();
//        getSum2();
        removeList();
    }

    private static void removeList() {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 5; i++)
            list.add(i);
        // list {0, 1, 2, 3, 4}
        for (int i = 0; i < list.size(); i++) {
            // index and number
            System.out.print(i + " " + list.get(i));
            if (list.get(i) % 2 == 0) {
                list.remove(list.get(i));
                System.out.print(" delete");
                i--; // 索引改变!
            }
            System.out.println();
        }
    }

    private static void getSum2() {
        Long startTime = System.nanoTime();
        int[] arry = {-5, -1, 0, 5, 9, 11, 13, 15, 22, 35, 46};
        int sumNumber = 31, last = 0;
        for (int i = 0; i < arry.length - 1; i++) {
            for (int j = i + 1; j < arry.length; j++) {
                last++;
                if (arry[i] + arry[j] == sumNumber) {
                    System.out.println("result2=" + arry[i] + "+" + arry[j]);
                    break;
                }
            }
        }
        Long endTime = System.nanoTime();
        System.out.println("consume=" + (endTime - startTime) + "      index=" + last);
    }

    private static void getSum() {
        Long startTime = System.nanoTime();
        int[] arry = {-5, -1, 0, 5, 9, 11, 13, 15, 22, 35, 46};
        int sumNumber = 31, index = 1, last = 0;
        for (int i = 0; i < arry.length / 2; ) {
            last++;
            if (arry[i] + arry[arry.length - index] > sumNumber) {
                index++;
            } else if (arry[i] + arry[arry.length - index] < sumNumber) {
                i++;
            } else {
                System.out.println("result=" + arry[i] + "+" + arry[arry.length - index]);
                break;
            }
        }
        Long endTime = System.nanoTime();
        System.out.println("consume=" + (endTime - startTime) + "      index=" + last);
    }

}
